extends CharacterBody2D
@export var max_health: int = 50
var current_health: int

@onready var sprite: Sprite2D = $Sprite2D

func _ready():
	current_health = max_health
	
	# 设置碰撞层为敌人层 (4)
	collision_layer = 4
	collision_mask = 1  # 可以与玩家碰撞

func take_damage(amount: int):
	current_health -= amount
	print("Enemy took ", amount, " damage! Health: ", current_health)
	
	# 受伤效果
	var tween = create_tween()
	tween.tween_property(sprite, "modulate", Color.RED, 0.1)
	tween.tween_property(sprite, "modulate", Color.WHITE, 0.1)
	
	if current_health <= 0:
		die()

func die():
	print("Enemy died!")
	queue_free()
